package cat.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import cat.entity.Article;
import cat.entity.Comment;
import cat.mapper.ArticleMapper;
import cat.mapper.CommentMapper;
import cat.service.CommentService;

@Service
public class CommentServiceImpl implements CommentService {
	
	@Resource
	CommentMapper commentMapper;
	
	@Resource
	ArticleMapper artileMapper;

	/**
	 * 查询最近的5条评论
	 */
	public List<Comment> listRecentComment(Integer n) {
		List<Comment> commentList = commentMapper.listRecentComment(n);
		for(int i=0;i<commentList.size();i++) {
			//得到评论信息中对应的文章ID
			int commentArticleId=commentList.get(i).getCommentArticleId();
			
			Article article=artileMapper.getArticleById(commentArticleId);
			commentList.get(i).setArticle(article);
		}
		
		return commentList;
	}
	
	public void delComment(Integer commentId) {
		commentMapper.delComment(commentId);
	}

}